#include "XmlSceneSerializer.h"
#include "OgreLogManager.h"
#include "SceneData.h"
#include "TerrainData.h"

using namespace Ogre;

CXmlSceneSerializer::CXmlSceneSerializer(void)
:m_pScene(NULL)
{
}

CXmlSceneSerializer::~CXmlSceneSerializer(void)
{
}

void CXmlSceneSerializer::LoadScene(const std::string& strFile, CSceneData* pScene)
{
	 LogManager::getSingleton().logMessage("CXmlSceneSerializer reading mesh data from " + strFile + "...");
	 TiXmlDocument* pXmlDoc = new TiXmlDocument(strFile.c_str());
	 m_pScene = pScene;

	 TiXmlElement* pXmlScene = pXmlDoc->FirstChildElement("Scene");
	 if(pXmlScene)
	 {
		 m_pScene->m_strFormateVersion = pXmlScene->Attribute("formateVersion");
		 m_pScene->m_strSceneName = pXmlScene->Attribute("name");

		 TiXmlElement* pXmlTerrain = pXmlScene->FirstChildElement("Terrain");
		 if(pXmlTerrain)
		 {
			 std::string str = pXmlTerrain->Attribute("name");
			 m_pScene->GetTerrainData()->LoadTerrainData(str);
		 }
	 }

	delete pXmlDoc;
}
